﻿
using System;
using System.IO;
using System.Collections.Generic;
using System.Globalization;

namespace ConsoleApplication1
{
    public class Record
    {
        public Record(decimal open, decimal close, decimal high, decimal low, int volume, DateTime date)
        {
            Open = open;
            Close = close;
            High = high;
            Low = low;
            Volume = volume;
            Date = date;

        }

        public decimal Open
        {
            get;
            internal set;
        }

        public decimal Close
        {
            get;
            internal set;
        }

        public decimal Low
        {
            get;
            internal set;
        }

        public decimal High
        {
            get;
            internal set;
        }

        public int Volume
        {
            get;
            internal set;
        }

        public DateTime Date
        {
            get;
            internal set;
        }

    }

    public class Data
    {
        public static List<Record> readFromFile(string path, DateTime dateFrom, DateTime dateTo)
        {
            List<Record> records = new List<Record>();

            TextReader tr = new StreamReader(path);
            tr.ReadLine();
            Record record;
            DateTime date;

            while (tr.Peek() > 0)
            {
                string line = tr.ReadLine();
                string[] split = line.Split(',');

                date = new DateTime(
                    Int32.Parse(split[1].Substring(0, 4)),
                    Int32.Parse(split[1].Substring(4, 2)),
                    Int32.Parse(split[1].Substring(6, 2))
                );

                if (date >= dateFrom && date <= dateTo)
                {
                    NumberFormatInfo numberFormat = new System.Globalization.NumberFormatInfo();
                    numberFormat.CurrencyDecimalSeparator = ".";
                    record = new Record(
                        Decimal.Parse(split[2], numberFormat),
                        Decimal.Parse(split[5], numberFormat),
                        Decimal.Parse(split[3], numberFormat),
                        Decimal.Parse(split[4], numberFormat),
                        Int32.Parse(split[6]),
                        date
                    );

                    records.Add(record);
                }
            }

            tr.Close();

            return records;
        }
    }
}